package cn.sdormitory.controller.evaluation;

import cn.sdormitory.common.api.CommonPage;
import cn.sdormitory.common.api.CommonResult;
import cn.sdormitory.evaluation.entity.StudentHelpEntity;
import cn.sdormitory.evaluation.entity.StudentHelpInfoEntity;
import cn.sdormitory.evaluation.entity.WorkDayEntity;
import cn.sdormitory.evaluation.service.StudentHelpService;
import cn.sdormitory.evaluation.vo.WorkDayVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Api(tags = "学生帮扶")
@RequestMapping("/studentHelp")
public class StudentHelpController {

    @Resource
    StudentHelpService studentHelpService;

    /**
     * 添加帮扶学生
     * @param vo
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/save")
    public CommonResult<CommonPage> save(@RequestBody StudentHelpEntity vo) throws Exception {
        int i = studentHelpService.saveStudentHelp(vo);
        if(i>0){
            return CommonResult.success();
        }
        return CommonResult.failed();
    }
    /**
     * 查询任务列表
     * @param vo
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/pageList")
    public CommonResult<CommonPage> pageList(@RequestBody StudentHelpEntity vo) throws Exception {

        IPage<StudentHelpEntity> workDayPageList = studentHelpService.pageList(vo);
        return CommonResult.success(CommonPage.restPage(workDayPageList));
    }

    /**
     * 添加帮扶记录学生
     * @param vo
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/saveHelpInfo")
    public CommonResult saveHelpInfo(@RequestBody StudentHelpInfoEntity vo) throws Exception {
        int i = studentHelpService.addHelpInfo(vo);
        if(i>0){
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    /**
     * 添加帮扶记录学生
     * @param vo
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/getHelpInfoListByHelpId")
    public CommonResult getHelpInfoListByHelpId(@RequestBody StudentHelpInfoEntity vo) throws Exception {
        List<StudentHelpInfoEntity> helpInfoListByHelpId = studentHelpService.getHelpInfoListByHelpId(vo);
        return CommonResult.success(helpInfoListByHelpId);
    }
}
